// This shader is based on the original work provided by NVIDIA CORPORATION
// at: http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf
// FXAA was shipped as part of NVIDIA Graphics SDK 11 Direct3D

#define FXAA_PRESET 3
#define FXAA_HLSL_4 1

#include "FxaaShader.fh"

cbuffer cbFXAA
{
    float2 rcpFrame; // { 1.0f/inputTextureWidth, 1.0f/inputTextureHeight }
};

SamplerState RTSampler
{
    AddressU = Clamp;
    AddressV = Clamp;
    AddressW = Clamp;
#if FXAA_PRESET <= 2
    MaxAnisotropy = 4;
#endif
};

Texture2D InputRTColor;

struct VS_OUT
{
    float4 Position : SV_POSITION;
    float2 TexCoord : TEXCOORD;
};


VS_OUT VS(uint vert_id : SV_VERTEXID)
{
    VS_OUT vOut;
    vOut.TexCoord = float2((vert_id << 1) & 2, vert_id & 2);
    vOut.Position = float4(vOut.TexCoord * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), 0.0f, 1.0f);
    return vOut;
}

float4 PS(VS_OUT pIn) : SV_TARGET
{
    FxaaTex tex = { RTSampler, InputRTColor };
    return float4(FxaaPixelShader(pIn.TexCoord.xy, tex, rcpFrame.xy), 1.0f);
}

technique10
{
    pass P0
    {
        SetVertexShader(CompileShader(vs_4_1, VS()));
        SetGeometryShader(NULL);
        SetPixelShader(CompileShader(ps_4_1, PS()));
    }
}

